<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" >
  <div class="panel-heading title"></div>
<div class="layui-card-body">
<form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
      <input name="id" hidden/>
      <input name="wdkhid" hidden/>
    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-md6">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-block">
                    <input type="lxr" name="lxr" placeholder="请输入联系人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">联系方式</label>
                <div class="layui-input-block">
                    <input type="lxr" name="lxdh" placeholder="请输入联系人" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">意向度</label>
        <div class="layui-input-block">
            <select id="kujbSCF" name="khjb" lay-filter="select-type" lay-verify="required">
                <option value="">请选择意向度</option>
            </select>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-col-md12">
            <label class="layui-form-label">跟进情况</label>
            <div class="layui-input-block">
                <textarea type="gjqk" name="gjqk" placeholder="请输入跟进情况" autocomplete="off" class="layui-input" id="gjqkinfo"></textarea>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-row">
            <div class="layui-col-md6">
                <label class="layui-form-label">下次联系时间</label>
                <div class="layui-input-block">
                    <input type="datetime-local" name="xclxtime" placeholder="请输入下次联系时间（年月日时分秒）" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">常用语</label>
                <div class="layui-input-block">
                    <select name="cyy" lay-filter="aihao">
                        <option value="">请选择常用语</option>
                        <option value="未联系到客户，无人接听。">未联系到客户，无人接听。</option>
                        <option value="未联系到客户，客户拒接。">未联系到客户，客户拒接。</option>
                        <option value="已联系到客户，客户表示不需要。">已联系到客户，客户表示不需要。</option>
                        <option value="已联系到客户，客户表示在忙，稍后联系。">已联系到客户，客户表示在忙，稍后联系。</option>
                        <option value="已联系到客户，客户表示有意向，加微信发资料，进一步沟通。">已联系到客户，客户表示有意向，加微信发资料，进一步沟通。</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

  <div class="layui-form-item layui-hide">
  <div class="layui-input-block">
    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit" id="submit">保存</button>
    <button  class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
  </div>
</div>
</form>
</div>
</div>

</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="javascript"> var wdkhIdVo =[[${wdkhId}]]  </script>
<script>
  //获取token
  var token = CoreUtil.getData("access_token");
  //地址栏转义token中的#号
  var tokenQuery = token.replace("#", "%23");
  var tableIns1;
  var table = layui.table;
  var form = layui.form;
  var layer = layui.layer;
  var $ = jQuery = layui.jquery;
  var laydate = layui.laydate;
  info();
  var isycVo;
  layui.use(['table', 'layer', 'laydate'], function () {
      //给表单赋值
      form.val("info", {
          wdkhid: wdkhIdVo,
      })
      //常用于监听 同步 跟进情况
      form.on('select(aihao)',function(data){
          $("#gjqkinfo").val(data.value)
      });

    //监听保存
    form.on('submit(submit)', function(data){
      if(data.field.id===undefined || data.field.id===null || data.field.id===""){
        CoreUtil.sendPost("/tGjjl/add",data.field,function (res) {
          parent.info();
        });
      }else {
        CoreUtil.sendPut("/tGjjl/update",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }
      return false;
    });
  });
  function info() {
      CoreUtil.sendGet("/tWdkh/infoData/", null, function (res) {
          var code = res.code;
          var data = res.data;
          //username、 khlySC 请选择客户来源、请选择意向度、请选择所属销售;
          if (code == 0) {
              //username
              var username = $("#username");
              $.each(data.username, function (index, item) {
                  if (!!item) {
                      username.append("<option value=" + item + ">" + item + "</option>");
                  }
              });
              //客户来源
              var khlySC = $("#khlySC");
              var khlySCF = $("#khlySCF");
              var khlySCFeidt = $("#khlySCFeidt");
              $.each(data.khly, function (index, item) {
                  khlySC.append("<option value=" + item + ">" + item + "</option>");
                  khlySCF.append("<option value=" + item + ">" + item + "</option>");
                  khlySCFeidt.append("<option value=" + item + ">" + item + "</option>");
              });
              //意向度
              var kujbSC = $("#kujbSC");
              var kujbSCF = $("#kujbSCF");
              var kujbSCFeidt = $("#kujbSCFeidt");
              $.each(data.hkjb, function (index, item) {
                  if (!!item) {
                      kujbSC.append("<option value=" + item.id + ">" + item.value + "</option>");
                      kujbSCF.append("<option value=" + item.id + ">" + item.value + "</option>");
                      kujbSCFeidt.append("<option value=" + item.id + ">" + item.value + "</option>");
                  }
              });
              //所属销售
              var ssxsSC = $("#ssxsSC");
              $.each(data.ssxs, function (index, item) {
                  if (!!item) {
                      ssxsSC.append("<option value=" + item + ">" + item + "</option>");
                  }
              });
              form.render("select");
              isycVo = data.isyc;
              infodata();
          }
      });
  };

  function infodata() {
      CoreUtil.sendPost("/tWdkh/infoDataById/"+wdkhIdVo, null, function (res) {
          var gjjl = res.data.gjjl;//跟进记录
          var data = res.data.wdkh;//客户详情
          qtdhdata = data.qtdh;
          var wLxdh = data.lxdh;
          if (data.lxdh.length == 11 && isycVo == 1) { //是否隐藏
              wLxdh = data.lxdh.replace(data.lxdh.substring(3, 7), "****");
          } else if (data.lxdh.length > 11 && isycVo == 1) { //是否隐藏
              wLxdh = data.lxdh.replace(data.lxdh.substring(3, 9), "****");
          }
          //给表单赋值
          form.val("info", {
              lxr: data.lxr,
              lxdh: wLxdh,
              khjb: data.khjb,
              xclxtime: data.xclxtime,
          });
      });
  }
</script>